import Vue from 'vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue'
import router from './core/router.js'
import Loading from './components/loading/loading'
import axios from 'axios'
import 'element-ui/lib/theme-chalk/display.css';



Vue.prototype.$axios = axios;
Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.component("Loading",Loading);//注册全局组件

// 全局常量
// Vue.prototype.$url= '/apis';
Vue.prototype.$url= 'http://127.0.0.1:88';
Vue.prototype.$musicApi= '/musicApi';

Vue.prototype.$ws= 'wss://tworice.cn/wss/';

let token = '';

axios.defaults.headers.common['token'] = token;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';

// 添加一个请求拦截器
axios.interceptors.request.use(function (config) {
      let user = window.sessionStorage.getItem('token');
      if (user!=''||user!=null) {
            token = user;
      }
      config.headers.common['token'] = token;
      //console.dir(config);
      return config;
}, function (error) {
      // Do something with request error
      console.info("error: ");
      console.info(error);
      return Promise.reject(error);
});

// 添加一个响应拦截器
// axios.interceptors.response.use(function (response) {
//   if (response.data && response.data.code) {
//     if (parseInt(response.data.code) === 108 || parseInt(response.data.code) === 109 || response.data.msg === 'TOKEN失效，请重新登录' || response.data.msg === 'TOKEN不存在') {
//       //未登录
//       response.data.msg = "登录信息已失效，请重新登录";
//       road.$message.error(response.data.msg);
//       routerIndex.push('/login');
//     }
//     if (parseInt(response.data.code) === -1) {
//       road.$message.error("请求失败");
//     }
//   }
//   return response;
// }, function (error) {
//   // Do something with response error
//   console.dir(error);
//   road.$message.error("服务器连接失败");
//   return Promise.reject(error);
// })


new Vue({
  router, 
  render: h => h(App),// 挂载到指定的页面节点
  data(){
    return{
      loading:true // 全局属性，通过$root
    }
  }
}).$mount('#app')